﻿using CustomModel;
using IDeskService;
using Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility;

namespace DeskInterfaceService
{
    public class ShopService:QuickPostBase,IShopService
    {
        public List<province> GetProvince(out string error)
        {
            this.ControllerAction = "shop/get-province-list";
            this.UseAuth = false;
            string res = this.PostData();
          
          var model  =  JsonConvert.DeserializeObject<JsonPageModel<province>>(res);
            if (model.state=="0")
            {
                error = "未获取到数据";
            }
            else
            {
                error = null;
            }
            return model.entities;

        }

        /// <summary>
        /// 根据省份id获得城市列表
        /// </summary>
        /// <param name="error"></param>
        /// <returns></returns>
        public List<city> GetCityByProvinceId(int id,out string error)
        {
            this.ControllerAction = "shop/get-citys-by-pid";
            this.UseAuth = false;
            this.param.Add("id", id);
            var res = this.PostData();
            var model = JsonConvert.DeserializeObject<JsonPageModel<city>>(res);
            if (model.state=="1")
            {
                error = null;
                return model.entities;
            }
            else
            {
                error = "未请求到城市数据";
                return null;
            }
        }

        /// <summary>
        /// 获得区县列表根据城市id
        /// </summary>
        /// <param name="id"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public List<area> GetAreaByCityId(int id,out string error)
        {
            this.ControllerAction = "shop/get-areas-by-cid";
            this.UseAuth = false;
            this.param.Add("id", id);
            var res = this.PostData();
            var model = JsonConvert.DeserializeObject<JsonPageModel<area>>(res);
            if (model.state=="1")
            {
                error = null;
                return model.entities;
            }
            else
            {
                error = "未请求到区/县数据";
                return null;
            }
        }
        /// <summary>
        /// 注册商铺
        /// </summary>
        /// <returns></returns>
        public bool RegistShop(RegistShopModel shop,out string error)
        {
            this.ControllerAction = "shop/regist-shop";
            this.UseAuth = false;
            this.param.Add("registmodel", JsonConvert.SerializeObject(shop,new JsonSerializerSettings { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii }));
            string res = this.PostData();
            var model = JsonConvert.DeserializeObject<JsonStringModel>(res);
            if (model.StateInt!=1)
            {
                error = model.Summary;
            }
            else
            {
                error = null;
            }
            return model.State;
        }

        public List<shopinfo> GetShopsInfo(int userid, ShopStatusEnum shopStatus, out string error)
        {
            throw new NotImplementedException();
        }
    }
}
